<?php
/**
 * Created by PhpStorm.
 * User: DJ
 * Date: 2018/9/13
 * Time: 17:58
 */

 namespace App\Extend\Admin\Common\Html;


class LayuiForm
{
    public $label = '';
    public $input = '';
    public $html = '';
    public $isLong = false;

    private $_newLine = "\r\n";

    public function __construct() {

    }

    /**
     * item 单个表单
     * @param $label
     * @param $input
     * @return string
     */
    public function itemOne($label, $input, $clues='') {
        if($clues) {
            $clues = '<div class="layui-form-mid layui-word-aux">'. $clues .'</div>';
        }

        $inputDivClass = 'layui-input-inline';
        if($this->flashIsLong()) {
            $inputDivClass = 'layui-input-block';
        }
        return '
        <div class="layui-form-item">
            <label class="layui-form-label">'. $label .'</label>
            <div class="'. $inputDivClass .'">
                '. $input .'
            </div>
            '. $clues .'
        </div>
        ';
    }

    /**
     * textarea
     * @param $label
     * @param $input
     * @return string
     */
    public function textarea($label, $input, $clues='') {
        if($clues) {
            $clues = '<div class="layui-form-mid layui-word-aux">'. $clues .'</div>';
        }

        return '
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">'. $label .'</label>
            <div class="layui-input-block">
                '. $input .'
            </div>
            '. $clues .'
        </div>
        ';
    }

    /**
     * item 多个表单
     * @param $inlineList
     * @return string
     */
    public function itemList($label, $inlineList, $clues='') {
        if($clues) {
            $clues = '<div class="layui-form-mid layui-word-aux">'. $clues .'</div>';
        }
        $html = '<div class="layui-form-item">';
        $html .= '<label class="layui-form-label">'. $label .'</label>';
        foreach($inlineList as $inlineInfo) {
            $html .= $inlineInfo;
        }
        $html .= $clues;
        $html .= '</div>';
        return $html;
    }

    /**
     * 单个行内表单
     * @param $label
     * @param $input
     * @return string
     */
    public function inlineOne($label, $input) {
        return '<div class="layui-inline">
                <label class="layui-form-label">'. $label .'</label>
                <div class="layui-input-inline">
                    '. $input .'
                </div>
            </div>';
    }



    //设置短连接线
    public function getShortLine() {
        return '<div class="layui-form-mid">-</div>' . $this->_newLine;
    }

    //获取长表单
    public function setIsLong($isLong) {
        $this->isLong = $isLong;
        return $this;
    }

    public function flashIsLong() {
        $isLong = $this->isLong;
        $this->setIsLong(false);
        return $isLong;
    }

    public function getConvExt($verify='',$title='') {
        $placeholder = '';
        if($title) {
            $placeholder = '请输入' . $title;
        }
        return [
            'lay-verify'    => $verify,
            'placeholder'   => $placeholder,
            'autocomplete'  => 'off',
            'class'         => 'layui-input',
        ];
    }

    //获取input+外围div
    public function getInputDiv($input, $class, $verify='') {
        $html = '<div class="' . $class . '" lay-verify="'. $verify .'">' . $this->_newLine;
        $html .= $input;
        $html .= '</div>' . $this->_newLine;
        return $html;
    }

    /*

    <div class="layui-form-item">
        <label class="layui-form-label">单行输入框</label>
        <div class="layui-input-block">
            <input name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input" type="text">
        </div>
    </div>

    */
}